﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Reflection;
using System.Text;
using System.Windows.Forms;

namespace myMoney
{
    public partial class Main : QT.Windows.Shell.GlassForm
    {
        #region Attributes

        public static string CurrentGuid = "";
        public static string CurrentUser = "";

        #region UserControl

        private File.ucMain myMain = null;
        private File.ucUsers myUsers = null;
        private File.ucChangePass myPass = null;

        private Finance.ucExpenses myExpenses = null;
        private Finance.ucRecord myRecord = null;
        private Finance.ucStatistics myStatistics = null;
        private Finance.ucChart myChart = null;

        private Setting.ucBank myBank = null;
        private Setting.ucClassify myClassify = null;

        private SystemManage.ucBank mySysBank = null;

        #endregion

        #endregion

        #region Form

        public Main()
        {
            InitializeComponent();
            if (!MoneyClass.User.IsAdmin(CurrentGuid))
            {
                this.toolStripMenuItem_Users.Visible = false;
                this.toolStripMenuItem_System.Visible = false;
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            toolStripMenuItem_Main_Click(this.toolStripMenuItem_Main, e);
            InitmenuStrip();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            this.menuStrip1.BackColor = AeroColor;
            this.statusStrip1.BackColor = AeroColor;
        }

        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            this.pbClose.Location = new Point(this.pTop.Width - this.pbClose.Width - 14, this.pbClose.Location.Y);
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);
            e.Cancel = true;

            if (MessageBox.Show("确认要退出吗？", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) return;

            e.Cancel = false;
        }

        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);
            Application.Exit();
        }

        #endregion

        #region Event

        #region menuStrip

        #region File

        private void toolStripMenuItem_Main_Click(object sender, EventArgs e)
        {
            if (!this.pMain.Contains(myMain))
            {
                myMain = new File.ucMain();
                myMain.Dock = DockStyle.Fill;
                this.pMain.Controls.Add(myMain);
            }
            else myMain.loadData();

            myMain.BringToFront();
            this.Text = this.pMain.Controls[0].Tag + " - " + ((AssemblyTitleAttribute)(Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false))[0]).Title + " - " + CurrentUser;
        }

        private void toolStripMenuItem_Users_Click(object sender, EventArgs e)
        {
            if (!this.pMain.Contains(myUsers))
            {
                myUsers = new File.ucUsers();
                myUsers.Dock = DockStyle.Fill;
                this.pMain.Controls.Add(myUsers);
                this.pMain.Tag = myUsers.Name;
            }

            myUsers.BringToFront();
            this.Text = this.pMain.Controls[0].Tag + " - " + ((AssemblyTitleAttribute)(Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false))[0]).Title + " - " + CurrentUser;
        }

        private void toolStripMenuItem_Pass_Click(object sender, EventArgs e)
        {
            if (!this.pMain.Contains(myPass))
            {
                myPass = new File.ucChangePass();
                myPass.Dock = DockStyle.Fill;
                this.pMain.Controls.Add(myPass);
                this.pMain.Tag = myPass.Name;
            }

            myPass.BringToFront();
            this.Text = this.pMain.Controls[0].Tag + " - " + ((AssemblyTitleAttribute)(Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false))[0]).Title + " - " + CurrentUser;
        }

        private void toolStripMenuItem_Switch_Click(object sender, EventArgs e)
        {
            CurrentUser = "";
            CurrentGuid = "";
            ((Login)this.Owner).Visible = true;
            ((Login)this.Owner).WindowState = FormWindowState.Normal;
            this.Dispose();
        }

        private void toolStripMenuItem_Exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        #endregion

        #region Finance

        private void ToolStripMenuItem_Expenses_Click(object sender, EventArgs e)
        {
            if (!this.pMain.Contains(myExpenses))
            {
                myExpenses = new Finance.ucExpenses();
                myExpenses.Dock = DockStyle.Fill;
                this.pMain.Controls.Add(myExpenses);
            }

            myExpenses.BringToFront();
            this.Text = this.pMain.Controls[0].Tag + " - " + ((AssemblyTitleAttribute)(Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false))[0]).Title + " - " + CurrentUser;
        }

        private void toolStripMenuItem_Record_Click(object sender, EventArgs e)
        {
            if (!this.pMain.Contains(myRecord))
            {
                myRecord = new Finance.ucRecord();
                myRecord.Dock = DockStyle.Fill;
                this.pMain.Controls.Add(myRecord);
            }

            myRecord.BringToFront();
            this.Text = this.pMain.Controls[0].Tag + " - " + ((AssemblyTitleAttribute)(Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false))[0]).Title + " - " + CurrentUser;
        }

        private void toolStripMenuItem_Statistics_Click(object sender, EventArgs e)
        {
            if (!this.pMain.Contains(myStatistics))
            {
                myStatistics = new Finance.ucStatistics();
                myStatistics.Dock = DockStyle.Fill;
                this.pMain.Controls.Add(myStatistics);
            }

            myStatistics.BringToFront();
            this.Text = this.pMain.Controls[0].Tag + " - " + ((AssemblyTitleAttribute)(Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false))[0]).Title + " - " + CurrentUser;
        }

        private void toolStripMenuItem_Chart_Click(object sender, EventArgs e)
        {
            if (!this.pMain.Contains(myChart))
            {
                myChart = new Finance.ucChart();
                myChart.Dock = DockStyle.Fill;
                this.pMain.Controls.Add(myChart);
            }

            myChart.BringToFront();
            this.Text = this.pMain.Controls[0].Tag + " - " + ((AssemblyTitleAttribute)(Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false))[0]).Title + " - " + CurrentUser;
        }

        #endregion

        #region Setting

        private void toolStripMenuItem_UserBank_Click(object sender, EventArgs e)
        {
            if (!this.pMain.Contains(myBank))
            {
                myBank = new Setting.ucBank();
                myBank.Dock = DockStyle.Fill;
                this.pMain.Controls.Add(myBank);
            }

            myBank.BringToFront();
            this.Text = this.pMain.Controls[0].Tag + " - " + ((AssemblyTitleAttribute)(Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false))[0]).Title + " - " + CurrentUser;
        }

        public void toolStripMenuItem_Classify_Click(object sender, EventArgs e)
        {
            if (!this.pMain.Contains(myClassify))
            {
                myClassify = new Setting.ucClassify();
                myClassify.Dock = DockStyle.Fill;
                this.pMain.Controls.Add(myClassify);
            }

            myClassify.BringToFront();
            this.Text = this.pMain.Controls[0].Tag + " - " + ((AssemblyTitleAttribute)(Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false))[0]).Title + " - " + CurrentUser;
        }

        #endregion

        #region System

        private void toolStripMenuItem_Bank_Click(object sender, EventArgs e)
        {
            if (!this.pMain.Contains(mySysBank))
            {
                mySysBank = new SystemManage.ucBank();
                mySysBank.Dock = DockStyle.Fill;
                this.pMain.Controls.Add(mySysBank);
            }

            mySysBank.BringToFront();
            this.Text = this.pMain.Controls[0].Tag + " - " + ((AssemblyTitleAttribute)(Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false))[0]).Title + " - " + CurrentUser;
        }

        #endregion

        #endregion

        #region PictureBox

        private void pbClose_MouseEnter(object sender, EventArgs e)
        {
            if (this.pMain.Controls.Count > 1) this.pbClose.Image = global::myMoney.Properties.Resources.close;
        }

        private void pbClose_MouseLeave(object sender, EventArgs e)
        {
            this.pbClose.Image = global::myMoney.Properties.Resources.close02;
        }

        private void pbClose_Click(object sender, EventArgs e)
        {
            if (this.pMain.Controls[0].Name=="ucMain") return;

            this.pMain.Controls.RemoveAt(0);
            this.Text = this.pMain.Controls[0].Tag + " - " + ((AssemblyTitleAttribute)(Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false))[0]).Title + " - " + CurrentUser;
        }

        #endregion

        #region Button

        private void btnMain_Click(object sender, EventArgs e)
        {
            toolStripMenuItem_Main_Click(this.toolStripMenuItem_Main, e);
        }

        private void btnExpenses_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem_Expenses_Click(sender, e);
        }

        #endregion

        #endregion

        #region Method

        private void InitmenuStrip()
        {

        }

        #endregion
    }
}
